package com.gtw.modules.sys.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.gtw.modules.sys.service.SysCommodityService;
import com.gtw.modules.dao.TbCommodityDao;
import com.gtw.modules.entity.TbCommodity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;


@Service("SysCommodityservice")
public class SysCommodityServiceImpl implements SysCommodityService {
    @Autowired
    private TbCommodityDao commodityDao;

    @Override
    public TbCommodity queryObject(Integer id) {
        return commodityDao.selectByPrimaryKey(id);
    }

    @Override
    public void save(TbCommodity commodity) {
        commodityDao.insert(commodity);
    }

    @Override
    public void update(TbCommodity commodity) {
        commodityDao.updateByPrimaryKey(commodity);
    }

    @Override
    public void delete(Integer id) {
        TbCommodity tcp = commodityDao.selectByPrimaryKey(id);
        tcp.setIsdelete(true);
        commodityDao.updateByPrimaryKey(tcp);
    }

    @Override
    public void deleteBatch(Integer[] ids) {
        for (int i = 0; i < ids.length; i++) {
            TbCommodity tcp = commodityDao.selectByPrimaryKey(ids[i]);
            tcp.setIsdelete(true);
            commodityDao.updateByPrimaryKey(tcp);
        }
    }

    @Override
    public Page<TbCommodity> queryPageList(Page<TbCommodity> page, Map<String, Object> map) {
        page.setRecords(commodityDao.queryPageList(page, map));
        return page;
    }

    @Override
    public List<TbCommodity> findAll() {
        return commodityDao.findAll();
    }
}
